<%@ page language="java" contentType="text/html; charset=utf-8"   pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<script language="javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>  
<title>嘉童游乐中心-采购订单</title>
<script type="text/javascript">
$(document).ready(function(){
	
	 initTab("form1", "table1", "foot1", initData);
	
});

function initTab(formId, tableId, footId, initData) {
	
	var form = $("#" + formId);
	var pagebean = new PageBean(form);
	pagebean.setCallback(initData);
	pagebean.setFootId(footId);
	pagebean.setTableId(tableId);
	setPagebeanObj(pagebean);
	pagebean.doPage();
}

function initData(data) { //初始化采购订单 列表
	
	if(data!=null){
		var parStatus=new Array("删除","草稿","审批中","完成-同意","完成-不同意"," 关闭");
		 
		$.each(data,function(ind,obj){
			var htm="<tr>";
			var indextd =ind+1;
			var dateApply =getSmpFormatDate(new Date(obj.applyTime), true);
			var statusValue =obj.status;
			var inputupdate ="getEditlUrl('"+obj.pkPurordId+"','edit')";
			var inputChuLidate ="getEditlUrl('"+obj.pkPurordId+"','chuli')";
			var inputChuTuiLidate ="getEditlUrl('"+obj.pkPurordId+"','chuli-tui')";
			var suppName =obj.supplierName;
			if(suppName ==null){
				suppName ="";
			}
			/**处理*/
			 var option_handle = '<td><input type="button" class="btn_l" value="处理" onClick="'+inputChuLidate+'"></td>';
			 
			/**退回处理重新提交*/
			var option_handle_re='<td><input type="button" class="btn_l" value="重新申请" onClick="'+inputChuTuiLidate+'"></td>';
			 
			htm+="<td>"+indextd+"</td>";
			htm+='<td class="lv"><a href="${basePath}scmInvocing/scmPurOrder/invoOrderNew.shtml?type=detail&pkPurordId='+obj.pkPurordId+'">'+obj.pkPurordId+'</a></td>';
			htm+=' <td>'+suppName+'</td>';
			htm+=' <td>'+dateApply+'</td>';
			htm+='<td>'+obj.userName+'</td>';
			htm+="<td>"+obj.workflowVo.statusDesc+"</td> ";
			htm+='<td>'+(obj.workflowVo.result == null ? "":obj.workflowVo.result)+'</td>';
			if(statusValue=="1"){//草稿
				var  delpurOrder="del_purOrder('"+obj.pkPurordId+"')";
			htm+=' <td><input type="button" class="btn_l" value="编辑" onClick="'+inputupdate+'"><input type="button" onClick="'+delpurOrder+'" class="btn_l ml10" value="删除"></td>';
			}else if(statusValue=="2"){//2 审批中
				 if(obj.workflowVo.isCurrtOpt == '1')
					 {
					 	if(obj.workflowVo.isStartUser == '1')
					 		{
					 		 htm += option_handle_re;//重新提交
					 		}
					 	else
					 		{
					 		htm += option_handle;//处理
					 		}
					 }
				 else
					{
						htm += '<td></td>';
					}
			}else{
				htm+='<td></td>';
			}
			htm+="</tr>";
			 $("#table1").find("tr:eq("+ind+")").after(htm);
		});
	}
}

function del_purOrder(id){
	 $.messager.confirm('提示', '确认要删除吗?', function(r) {
		if(r){
			$.ajax({ 
				url: "${basePath }scmInvocing/scmPurOrder/delPurOrder.shtml",
				data:"fkPurordId="+id,
				type:'POST',
				success: function(data){
					initTab("form1", "table1", "foot1", initData);
					alertInfo($common_delete_success);
		      	},
				error : function(XMLHttpRequest) {
					ajaxError(XMLHttpRequest);
				}
			});
		}
	 });
}

function getEditlUrl(pkPurordId,type){
	if(type=="edit"){
	window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNewGundong.shtml?supplyId=&type='+type+'&pkPurordId='+pkPurordId;
	}else if(type=="chuli"){
		window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNew.shtml?supplyId=&type='+type+'&pkPurordId='+pkPurordId;
	}else if(type=="chuli-tui"){
		window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNewGundong.shtml?supplyId=&type='+type+'&pkPurordId='+pkPurordId;
	}
	}

function searchPurOrder(){
	var pkPurordIdSearch =$("#pkPurordIdSearch").val();
	if(pkPurordIdSearch!=""){
		$("#pkPurordId").val(pkPurordIdSearch);
	}else{
		$("#pkPurordId").val("");
	}
	var startTimeShow =$("#startTimeShow").val();
	var endTimeShow =$("#endTimeShow").val();
	if(startTimeShow !=""){
		$("#startApplyTime").val(startTimeShow);
	}else{
		$("#startApplyTime").val("");
	}
	
	if(endTimeShow !=""){
		$("#endApplyTime").val(endTimeShow);
	}else{
		$("#endApplyTime").val("");
	}
	select1("form1",initData);
}

 function resets(){
	 $("#pkPurordId").val("");
	 $("#startApplyTime").val("");
	 $("#endApplyTime").val("");
	 $("#startTimeShow").val("");
	 $("#endTimeShow").val("");
	 $("#pkPurordIdSearch").val("");
	 initTab("form1", "table1", "foot1", initData);
 }

function afterDate(){
	var startDateShow =$("#startTimeShow").val();
	var afterDate="";
	if(startDateShow!=""){
		afterDate = startDateShow;
	}
	  
	 return afterDate;
}

//设置pageNo为1
function select1(formId,initData){
	$("#"+formId+ " input:hidden[name='pageNo']").val(1);
	initTab(formId, "table1", "foot1", initData);
}

//跟换门店
function branSelectFun() {
	var branVal  = $("#branIdSelect").val();
	if(branVal == -1)
		{
			$("#fkBranId").val("");
		}
	else
		{
			$("#fkBranId").val(branVal);
		}
}
</script>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
      <shiro:hasPermission name="scmInvocing/productInfo/forwardToProductInfo.shtml">
    				  <li><a href="${basePath}scmInvocing/productInfo/forwardToProductInfo.shtml"><i class="nav_icon_b"></i><br>商品信息</a></li>
    		</shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/countUnit/forwardToUnitInfo.shtml">
    		 		<li><a href="${basePath}scmInvocing/countUnit/forwardToUnitInfo.shtml"><i class="nav_icon_b"></i><br>单位设置</a></li>
    		 </shiro:hasPermission>
    		 <shiro:hasPermission name="scmInvocing/supplier/forwardToSupply.shtml">
    		 		   <li><a href="${basePath}scmInvocing/supplier/forwardToSupply.shtml"><i class="nav_icon_a"></i><br>供应商信息</a></li>
    		 </shiro:hasPermission>
    		  <shiro:hasPermission name="scmInvocing/priceManager/forwardToList.shtml">
    		 		  <li><a href="${basePath}scmInvocing/priceManager/forwardToList.shtml"><i class="nav_icon_f"></i><br>价格管理</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPurOrder/findInvoPurOrder.shtml">
            	  <li  class="content_hover"><a href="${basePath}scmInvocing/scmPurOrder/findInvoPurOrder.shtml"><i class="nav_icon_b"></i><br>采购订单</a></li>
    		 </shiro:hasPermission>
    		   <shiro:hasPermission name="scmInvocing/scmPayForm/findInvoOrderPay.shtml">
           		   <li><a href="${basePath}scmInvocing/scmPayForm/findInvoOrderPay.shtml"><i class="nav_icon_b"></i><br>付款申请</a></li>
    		 </shiro:hasPermission></ul>
    </div>
    <div class="content_r mt10">
    	<div class="p20">
		<div class="file_single_dl f14 fixed">
			<dl>
				 <dd style="width:530px !important;">
		              <label>申请时间：</label>
		                         <input type="text" id="startTimeShow" class="Wdate iput_t w150" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowWeek:true,isShowClear:true,readOnly:true})">
						<span>至</span>
						<input type="text" id="endTimeShow" class="Wdate iput_t w150" onClick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{afterDate()}',isShowWeek:true,isShowClear:true,readOnly:true})">      
		          </dd>
		          <dd><label>采购订单号：</label><input id="pkPurordIdSearch" type="text" class="iput_t w200"></dd>
		          <dd><label>所属门店：</label>
	                		<!----select--->
	                  	 	<div class="uboxstyle">
	                        	<select name="branIdSelect" id="branIdSelect" onchange="branSelectFun();">
	                        	<c:if test="${isZongBU == 1}">
	                        	<option value="-1" selected="selected">全部</option>
	                        	</c:if>
                        		<c:forEach items="${branList}" var="bran">
                        			<option value="${bran.pkBranId}">${bran.branName}</option>
                        		</c:forEach>
	                        	</select>
	                   		 </div>
	                   		 <!----select--->
                 		</dd>
			   	  <dd class="fr">
		                        <!-- <input type="button" class="btn ml10" onclick="resets()" value="重置"> -->
			             <input type="button" class="btn ml10" onclick="searchPurOrder()" value="查询">
			             <shiro:hasPermission name="scmorder:add">
			             <input class="btn ml10" type="button" value="创建采购订单" onClick="window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNewGundong.shtml?pkPurordId=&supplyId=&type='"> 
	            		 </shiro:hasPermission><!-- <input class="btn ml10" type="button" value="创建采购订单" onClick="window.location.href='${basePath}scmInvocing/scmPurOrder/invoOrderNew.shtml?pkPurordId=&type=add'"> -->
		            
		          </dd>
		          </dl> 
        </div>
       
        <div class="mt10">
          	<ul class="fixed" id="tab_conbox_a">
                <li class="p10 h450" style="margin-left:10px">
            	 <form action="${basePath}scmInvocing/scmPurOrder/findScmPurOrderEntityList.shtml" method="post" id="form1">
                  <input type="hidden" name="pageSize" value="10"> <input type="hidden" name="pageNo" value="1">
                  <input type="hidden" name="pkPurordId" id="pkPurordId">
                  <input type="hidden" name="fkBranId" id="fkBranId">
                    <input type="hidden" name="startApplyTime" id="startApplyTime" >
                  <input type="hidden" name="endApplyTime" id="endApplyTime">
                <table class="table" id="table1">
                    	<tr>
                        	<th>序号</th>
                            <th>采购订单编号</th>
                            <th>供应商名称</th>
                            <th>申请日期</th>
                            <th>申请人</th>
                            <th>审批状态</th> 
                            <th>审批结果</th>
                            <th>操作</th>
                        </tr>
                        	
                         
                    </table>
                    
                    <!---翻页-->
         			 <div class="page fr m10" id="foot1">
							</div>
                    <!----->
                    </form>
                </li>
                </ul>
                </div>
        </div>
    </div>
</div>

</body>
</html>






